#ifndef COMMON_H
#define COMMON_H

// define types
typedef unsigned char      u8;
typedef unsigned short     u16;
typedef unsigned int       u32;
typedef unsigned long int  u32l;
typedef unsigned long long u64;

typedef char      s8;
typedef short     s16;
typedef int       s32;
typedef long int  s32l;
typedef long long s64;
typedef float     f32;
typedef double    d64;

// define micro
#define SIZE_SSMALL 8
#define SIZE_VSMALL 16
#define SIZE_EFRAME 22
#define SIZE_LSMALL 32
#define SIZE_SMALL  64
#define SIZE_MEDIUM 256
#define SIZE_LARGE  1024
#define SIZE_SLARGE 4 * 1024
#define SIZE_ELARGE 16 * 1024
#define SIZE_HUGE   1024 * 1024

#define ETHERNET_INTERFACE  "ens37"
#define MULTICAST_IPADDR    "224.0.0.1"
#define MULTICAST_RECV_PORT 57391
#define MULTICAST_SEND_PORT 57392

/* define ground manager */
#define MAVLINK_MSG_HEAD_0        0x46
#define MAVLINK_MSG_HEAD_1        0x4E
#define MAVLINK_MSG_CLASS         0x7E
#define MAVLINK_HEADER_SIZE       6
#define MAVLINK_CRC16_SIZE        2
#define MAVLINK_HEADER_CRC16_SIZE 8
#define MAVLINK_SET               0
#define MAVLINK_GET               1

////////// recv message ID
#define MAVLINK_MSG_ID_ATTITUDE 0x1E
#define MAVLINK_MSG_ID_POSITION 0x21

////////// send message ID
#define MAVLINK_MSG_ID_COMMAND 0x4C

#pragma pack(1)

// define struct
typedef struct mavlink_string_t
{
    u8 STX_0;     /* header first 0x46 */
    u8 STX_1;     /* header second 0x4E */
    u8 CLASS;     /* class id 0xFF */
    u8 LEN;       /* payload length */
    u8 SEQ;       /* sequence number */
    u8 MsgID;     /* message id */
    u8 Data[258]; /* data */
} TMavlinkString;

typedef struct mavlink_control_t
{
    f32 Param_1;          /* parameter 1 */
    f32 Param_2;          /* parameter 2 */
    f32 Param_3;          /* parameter 3 */
    f32 Param_4;          /* parameter 4 */
    f32 Param_5;          /* parameter 5 */
    f32 Param_6;          /* parameter 6 */
    f32 Param_7;          /* parameter 7 */
    u16 command;          /* command ID */
    u8  target_system;    /* 0x4E */
    u8  target_component; /* 0x7E */
    u8  confirmation;     /* command times */
} TMavlinkControl;

typedef struct mavlink_attitude_t
{
    u32 time;  /* boot time */
    f32 roll;  /* roll angle */
    f32 pitch; /* pitch angle */
    f32 yaw;   /* yaw angle */
} TMavlinkAttitude;

typedef struct mavlink_position_t
{
    u32 time;          /* boot time */
    s32 lat;           /* Aircraft latitude */
    s32 lon;           /* Aircraft longitude */
    s32 alt;           /* Aircraft altitude */
    s32 relative_alt;  /* Relative altitude of aircraft */
    s16 vx;            /* X-axis velocity */
    s16 vy;            /* Y-axis velocity */
    s16 vz;            /* Z-axis velocity */
    u16 distance2home; /* distance to home */
} TMavlinkPosition;

#pragma pack()

#endif // COMMON_H
